import { getToken } from "@/utils/auth";
var axios = require("axios");
import { compareImageSize } from "@/utils/imageUtils"
const limitSize = 2
const videoLimitSize = 3

export default {
    placeholder: "请输入内容...",
    MENU_CONF: {
        uploadImage: {
            // 用户自定义上传图片
             customUpload(file, insertFn) {
                // console.log(file, insertFn, "----------------------------");

                compareImageSize(file, limitSize * 1024 * 1024, true).then(async newFile => {
                    // console.log(newFile, 'newFile---')
                    var FormData = require("form-data");
                    var data = new FormData();
                    // data.append("image", file); // file 即选中的文件
                    data.append("file", newFile); // file 即选中的文件

                    var config = {
                        method: "post",
                        url: process.env.VUE_APP_BASE_API + "/fileController/uploadFile", //上传图片地址
                        headers: {
                            "Content-Type": "multipart/form-data",
                            token: getToken(),
                        },
                        data: data,
                    };

                    let res = await axios(config);
                    if (res) {
                        let url = res.data.data; //拼接成可浏览的图片地址
                        insertFn(url, "", url); //插入图片
                    } else {
                        // insertFn(url, "使用说明", url); //插入图片
                    }
                }).catch(err=>{
                    console.log(err)
                })
                return

            },
        },
        uploadVideo: {
             customUpload(file, insertFn) {
                // console.log(file, insertFn, "----------------------------");

                compareImageSize(file, videoLimitSize * 1024 * 1024, false).then(async newFile => {
                    // console.log(newFile, 'newFile---')
                    var FormData = require("form-data");
                    var data = new FormData();
                    // data.append("image", file); // file 即选中的文件
                    data.append("file", newFile); // file 即选中的文件

                    var config = {
                        method: "post",
                        url: process.env.VUE_APP_BASE_API + "/fileController/uploadFile", //上传图片地址
                        headers: {
                            "Content-Type": "multipart/form-data",
                            token: getToken(),
                        },
                        data: data,
                    };

                    let res = await axios(config);
                    if (res) {
                        let url = res.data.data; //拼接成可浏览的图片地址
                        insertFn(url, "", url); //插入图片
                    } else {
                        // insertFn(url, "使用说明", url); //插入图片
                    }
                }).catch(err=>{
                    console.log(err)
                })
                return

            },
        },
    },
}